﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace SZ.Mech
{
    public class CompProperties_AbilityDragonWeather: CompProperties_AbilityEffect
    {
        public int duration = 3600;
        public ThingDef projectileDef;
        public CompProperties_AbilityDragonWeather()
        {
            compClass = typeof(CompAbilityEffect_DragonWeather);
        }
    }


    public class CompAbilityEffect_DragonWeather : CompAbilityEffect
    {
        public CompProperties_AbilityDragonWeather Properties
        {
            get
            {
                var p = (CompProperties_AbilityDragonWeather)props;

                return p;
            }
        }

        public override bool CanApplyOn(LocalTargetInfo target, LocalTargetInfo dest)
        {
            return base.CanApplyOn(target, dest);
        }

        //public override bool CanApplyOn(LocalTargetInfo target, LocalTargetInfo dest)
        //{
        //    return true;

        //    //var p = this.props;
        //    //var g = this.Properties;

        //    //return base.CanApplyOn(target, dest);
        //}
        private Pawn Pawn => parent.pawn;
        public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
        {

            ///发射投射
            ((Projectile)GenSpawn.Spawn(Properties.projectileDef, parent.pawn.Position, Pawn.Map)).Launch(Pawn, Pawn.DrawPos, target.Cell, target.Cell, ProjectileHitFlags.IntendedTarget);


            ///创造天气
            Map map = parent.pawn.Map;
            Thing conditionCauser = GenSpawn.Spawn(ThingDefOf.Flashstorm, target.Cell, parent.pawn.Map);
            GameCondition_Flashstorm gameCondition_Flashstorm = (GameCondition_Flashstorm)GameConditionMaker.MakeCondition(GameConditionDefOf.Flashstorm);

            gameCondition_Flashstorm.Duration = Properties.duration;
            gameCondition_Flashstorm.suppressEndMessage = true;
            gameCondition_Flashstorm.conditionCauser = this.parent.pawn;
            map.gameConditionManager.RegisterCondition(gameCondition_Flashstorm);

            //1.5找不到太阳耀斑了
            //GameCondition_DisableElectricity gameCondition_DisableElectricity = (GameCondition_DisableElectricity)GameConditionMaker.MakeCondition(GameConditionDefOf.SolarFlare);
            //gameCondition_DisableElectricity.Duration = Properties.duration;
            //gameCondition_DisableElectricity.suppressEndMessage = true;
            //gameCondition_DisableElectricity.conditionCauser = this.parent.pawn;
            //map.gameConditionManager.RegisterCondition(gameCondition_DisableElectricity);
            base.Apply(target, dest);

        }


    }
}
